/**
 * @file test_Log.cpp
 * @author  haifeng (haifengxiao@icloud.com)
 * @brief
 * @version 0.1
 * @date 2021-07-06
 *
 * @copyright Copyright (c) 2021
 *
 */
#include <gtest/gtest.h>
#include <gmock/gmock.h>

#include <string>
#include <iostream>

#include "LogAppender.h"
#include "StdoutLogAppender.h"
#include "LogLevel.h"
#include "Logger.h"
#include "LoggerManager.h"

using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::MockFunction;

TEST(DEBUG_MACRO, LOG_TEST) {
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger);
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));
    logger->setLevel(Chen::Log::LogLevel::Level::DEBUG_);
    EXPECT_EQ(Chen::Log::LogLevel::Level::DEBUG_, logger->getLevel());
}

TEST(INFO_MACRO, LOG_TEST) {
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger);
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));
    logger->setLevel(Chen::Log::LogLevel::Level::INFO);
    EXPECT_EQ(Chen::Log::LogLevel::Level::INFO, logger->getLevel());
}

TEST(WARN_MACRO, LOG_TEST) {
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger);
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));
    logger->setLevel(Chen::Log::LogLevel::Level::WARN);
    EXPECT_EQ(Chen::Log::LogLevel::Level::WARN, logger->getLevel());
}

TEST(ERROR_MACRO, LOG_TEST) {
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger);
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));
    logger->setLevel(Chen::Log::LogLevel::Level::ERROR);
    EXPECT_EQ(Chen::Log::LogLevel::Level::ERROR, logger->getLevel());
}

TEST(FATAL_MACRO, LOG_TEST) {
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger);
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));
    logger->setLevel(Chen::Log::LogLevel::Level::FATAL);
    EXPECT_EQ(Chen::Log::LogLevel::Level::FATAL, logger->getLevel());
}

void test_macro() {
    CHEN_LOG_DEBUG(CHEN_LOG_ROOT()) << "something";
}

void test_nomacro() {
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger("test_logger"));
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));
    std::string name = "testevent";
    Chen::Log::LogEvent::ptr e(new Chen::Log::LogEvent(logger, Chen::Log::LogLevel::Level::INFO, __FILE__, __LINE__, 0, 1, 3, 4, name));
    logger->log(Chen::Log::LogLevel::DEBUG_, e);
}


int main(int argc, char** argv) {
    //test_macro();
    test_nomacro();
    Chen::Log::Logger::ptr logger(new Chen::Log::Logger);
    logger->addAppender(Chen::Log::LogAppender::ptr(new Chen::Log::StdoutLogAppender));

    std::cout << logger->getName() << std::endl;
    std::string name = "main";
    std::cout << "beginning" << std::endl;


#ifdef A
    Chen::Log::LogEvent::ptr e(new Chen::Log::LogEvent(logger, Chen::Log::LogLevel::Level::INFO, __FILE__, __LINE__, 0, 1, 3, 4, name));
    e->getSS() << "hello Chen log";
    std::cout << "here" << std::endl;
    logger->log(Chen::Log::LogLevel::DEBUG_, e);
#endif  

    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();

    return 0;
}
